package com.chengww.grab_rp.utils

import java.security.MessageDigest

/**
 * Created by chengww on 2/20/21
 * @author chengww
 */
//MD5加密不可逆
object MD5 {
    fun digest(password: String): String {
        return try {
            val digest: MessageDigest = MessageDigest.getInstance("MD5")
            val bytes: ByteArray = digest.digest(password.toByteArray())
            val sb = StringBuilder()
            for (b in bytes) {
                val c: Int = b.toInt() and 0xff
                val result = Integer.toHexString(c)
                if (result.length < 2) {
                    sb.append(0)
                }
                sb.append(result)
            }
            sb.toString()
        } catch (ex: Exception) {
            ""
        }
    }
}